#!/usr/bin/env python
# -*- coding: utf-8 -*-
# from Public.BasePage import BasePage
# from Public.maxim_monkey import Maxim
from Public.Decorator import *
from uiautomator2 import UiObjectNotFoundError


class WxHomePage(BasePage):
    @teststep
    def wait_page(self):
        try:
            if self.d(resourceId="android:id/text1").wait(timeout=15):
                if self.d(resourceId="android:id/text1").get_text() == '微信':
                    log.i('成功登录微信首页')
                    pass
            else:
                raise Exception('Not in HonePage')
        except Exception:
            raise Exception('Not in HonePage')

    @teststep
    def click_addr_book_tab(self):
        '''
        点击底部通讯录tab
        :param inst: tab的位数
        :return:
        '''
        ele = self.d.xpath(
            '//*[@resource-id="com.tencent.mm:id/bw"]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.LinearLayout[1]')
        text = ele.get_text()
        ele.click()
        time.sleep(5)
        log.i('点击Tab %s' % text)

    @teststep
    def click_OA_item(self):
        '''
        点击公众号按钮
        :param inst: tab的位数
        :return:
        '''
        ele = self.d(text="公众号")
        text = ele.get_text()
        ele.click()
        time.sleep(2)
        log.i('点击Tab %s' % text)


if __name__ == '__main__':
    from Public.Log import Log
    WxHomePage().set_driver(None)
    WxHomePage().click_addr_book_tab()
